//
//  FFSessionManager.m
//  Common
//
//  Created by IT.Bear on 16/8/29.
//  Copyright © 2016年 IT.Bear. All rights reserved.
//

#import "AFNetworking.h"
#import "SessionManager.h"

static AFURLSessionManager *urlsession ;
@implementation SessionManager


+(AFURLSessionManager *)sharedURLSession{
    static dispatch_once_t onceToken2;
    dispatch_once(&onceToken2, ^{
        urlsession = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
        urlsession.responseSerializer = [AFHTTPResponseSerializer serializer];
    });
    return urlsession;
}

@end

@implementation HTTPSessionManager
+(AFHTTPSessionManager *)sharedURLSession{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //最大请求并发任务数
    manager.operationQueue.maxConcurrentOperationCount = 10;
    
    // 请求格式
    // AFHTTPRequestSerializer      二进制格式
    // AFJSONRequestSerializer      JSON
    // AFPropertyListRequestSerializer  PList(是一种特殊的XML,解析起来相对容易)
    
    manager.requestSerializer = [AFHTTPRequestSerializer serializer]; // 上传普通格式
    
    // 超时时间
    manager.requestSerializer.timeoutInterval = 15.0f;
    // 设置请求头
    [manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Content-Encoding"];
    // 设置接收的Content-Type
    manager.responseSerializer.acceptableContentTypes = [[NSSet alloc] initWithObjects:@"application/xml", @"text/xml",@"text/html", @"application/json",@"text/plain",nil];
    
    // 返回格式
    // AFHTTPResponseSerializer      二进制格式
    // AFJSONResponseSerializer      JSON
    // AFXMLParserResponseSerializer   XML,只能返回XMLParser,还需要自己通过代理方法解析
    // AFXMLDocumentResponseSerializer (Mac OS X)
    // AFPropertyListResponseSerializer  PList
    // AFImageResponseSerializer     Image
    // AFCompoundResponseSerializer    组合
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];//返回格式 JSON
    //设置返回C的ontent-type
    manager.responseSerializer.acceptableContentTypes=[[NSSet alloc] initWithObjects:@"application/xml", @"text/xml",@"text/html", @"application/json",@"text/plain",nil];
    
    return manager;
}

@end
